<?php

class IO_MainFunction 
{
	
	function getPreventspam()
	{
		require_once 'Preventspam/preventspam.class.php';
		$objSpam = new PreventSpam();
		$hiddenField = $objSpam -> getHiddenCssField($strCode);
		
		session_register("REGISTER_PREVENT_SPAM");
		$_SESSION["REGISTER_PREVENT_SPAM"] = $strCode;
		
		return $hiddenField;
	}
	
	function getSessionMsgGame()
	{
		$strMsg = '';
		if ( isset($_SESSION['SESSION_MSG_GAME']) )
		{
			$strMsg = $_SESSION['SESSION_MSG_GAME'];
			unset($_SESSION['SESSION_MSG_GAME']);
		}
		
		return $strMsg;
	}
	
	function setSessionMsgGame($p_strMsg = '')
	{
		if ( !isset($_SESSION['SESSION_MSG_GAME']) )
			session_register('SESSION_MSG_GAME');
		
		$_SESSION['SESSION_MSG_GAME'] = $p_strMsg;
	}
	
	function getSessionMsg()
	{
		$strMsg = '';
		if ( isset($_SESSION['SESSION_MSG']) )
		{
			$strMsg = $_SESSION['SESSION_MSG'];
			unset($_SESSION['SESSION_MSG']);
		}
		
		return $strMsg;
	}
	
	function setSessionMsg($p_strMsg = '')
	{
		if ( !isset($_SESSION['SESSION_MSG']) )
			session_register('SESSION_MSG');
		
		$_SESSION['SESSION_MSG'] = $p_strMsg;
	}
	
	function makeTitleUrl($p_strTitle)
	{
		$str = trim($p_strTitle);
		$str = preg_replace('/\s\s+/', ' ', $str);
		$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
		$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
		$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
		$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
		$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
		$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
		$str = preg_replace("/(đ)/", 'd', $str);
		$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
		$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
		$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
		$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
		$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
		$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
		$str = preg_replace("/(Đ)/", 'D', $str);
		
		$strReturn = '';
		for( $i = 0; $i <= strlen($str); $i++ )
		{
			if ( preg_match('/^[a-zA-Z0-9\-]$/i', substr($str, $i, 1)) )
				$strReturn .= substr($str, $i, 1);
			elseif ( substr($str, $i, 1) == ' ' )
				$strReturn .= '-';
		}
		return ($strReturn);
	}
	
	function getFileExt($filename)
	{        
			$getExt = explode ('.', $filename);
		$file_ext = $getExt[count($getExt)-1];
		return $file_ext;
	}
    
   
  function convertDectohex($p_intNumber)
	{
        return strtoupper(dechex($p_intNumber + NUMBER_DECDEXDEC));
	}
	
	function convertHexToDec($p_intNumber)
	{
		return (hexdec($p_intNumber) - NUMBER_DECDEXDEC);
	}

        function curPageURL() {
             $pageURL = 'http';
             if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
             $pageURL .= "://";
             if ($_SERVER["SERVER_PORT"] != "80") {
              $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
             } else {
              $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
             }
             return $pageURL;
        }
 
        function getToken(){
            $_SESSION['token']  = uniqid();
            return $_SESSION['token'];
        }

        function compareToken($token){
            $result = $token==$_SESSION['token'];
            $_SESSION['token'] = uniqid();
            return $result;

        }

}
?>